package com.yllt4cloud.push.config;

import com.yllt4cloud.push.server.FiexThreadPoolExecutor;
import com.yllt4cloud.push.server.HandlerDispatcher;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class NettyConfig {


    @Value("${app.dispatcher.pool.corePoolSize}")
    private int corePoolSize;

    @Value("${app.dispatcher.pool.maximumPoolSize}")
    private int maximumPoolSize;

    @Value("${app.dispatcher.pool.keepAliveSecond}")
    private long keepAliveSecond;

    @Bean(destroyMethod="shutdown") //1
    FiexThreadPoolExecutor getFiexThreadPoolExecutor(){
        return new FiexThreadPoolExecutor(corePoolSize,maximumPoolSize,keepAliveSecond);
    }


    @Primary
    @Bean(initMethod="init",destroyMethod="stop") //1
    HandlerDispatcher getHandlerDispatcher(){
        HandlerDispatcher r = new HandlerDispatcher();
        r.setMessageExecutor(getFiexThreadPoolExecutor());
        return r;
    }

}
